package game.gfx;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageReader
{
	public int width;
	public int height;
	
	protected int[][] pixelData;
	protected int[][] pixelDataRGB;
	
	public ImageReader(String path)
	{
		BufferedImage image = null;
		String workingDir = System.getProperty("user.dir");
		
		try
		{ 
			File imageFile = new File(workingDir + path);
			image = ImageIO.read(imageFile); 
		}
		catch (IOException e) { e.printStackTrace(); }
		
		this.width = image.getWidth();
		this.height = image.getHeight();
		
		int[] pixels = image.getRGB(0, 0, width, height, null, 0, width);
		
		this.pixelData = new int[width][height];
		
		int index = 0;
		for (int y = 0; y < height; y++)
		{
			for (int x = 0; x < width; x++)
			{
				pixelData[x][y] = pixels[index];
				index++;
			}
		}		
	}
	
	public int[][] getPixelData()
	{
		return pixelData;
	}
	
	public int[][] getPixelDataRGB()
	{
		return pixelData;
	}
	
	public int getWidth()
	{
		return width;
	}
	
	public int getHeight()
	{
		return height;
	}
}
